package com.example.bingobox.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.bingobox.R;
import com.example.bingobox.model.State.Location;

import java.util.List;

public class TravelCityAdapter extends RecyclerView.Adapter<TravelCityAdapter.ViewHolder> {
    private final List<Location> cities;
    private final OnCityRemoveListener listener;

    public TravelCityAdapter(List<Location> cities, OnCityRemoveListener listener) {
        this.cities = cities;
        this.listener = listener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_travel_city, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Location city = cities.get(position);
        holder.cityName.setText(city.getName());
        holder.btnRemove.setOnClickListener(v -> {
            if (listener != null) {
                listener.onCityRemove(city);
            }
        });
    }

    @Override
    public int getItemCount() {
        return cities.size();
    }

    public interface OnCityRemoveListener {
        void onCityRemove(Location city);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        final TextView cityName;
        final ImageButton btnRemove;

        ViewHolder(View view) {
            super(view);
            cityName = view.findViewById(R.id.city_name);
            btnRemove = view.findViewById(R.id.btn_remove);
        }
    }
} 